/***********************************************************************
	$Id:$
	purpose:	Defines interface for the hgeLogger class
*************************************************************************/

#ifndef _HgeLogger_h_
#define _HgeLogger_h_

#include <fstream>
#include <sstream>
#include <vector>
#include <utility>
#include "hgeSingleton.h"
#include "hgeForwardRef.h"

#if defined(_MSC_VER)
#	pragma warning(push)
#	pragma warning(disable : 4275)
#	pragma warning(disable : 4251)
#endif

/*!
\brief
	Enumeration of logging levels
*/
enum LoggingLevel
{
	Errors,			//!< Only actual error conditions will be logged.
    Warnings,       //!< Warnings will be logged as well.
	Standard,		//!< Basic events will be logged (default level).
	Informative,	//!< Useful tracing (object creations etc) information will be logged.
	Insane			//!< Mostly everything gets logged (use for heavy tracing only, log WILL be big).
};

class hgeLogger : public Singleton <hgeLogger>
{
public:
	hgeLogger();
	virtual ~hgeLogger();


	//Set the level of logging information that will get out to the log file
	void	setLoggingLevel(LoggingLevel level)		{d_level = level;}


	//return the current logging level setting
	LoggingLevel	getLoggingLevel(void) const		{return d_level;}


	//Add an event to the log.
	void logEvent(const String& message, LoggingLevel level = Standard);

	//Set the name of the log file where all subsequent log entries should be written.
    //The interpretation of file name may differ depending on the concrete logger
    //implementation.
    virtual void setLogFilename(const String& filename, bool append = false);

protected:
	LoggingLevel	d_level;		//!< Holds current logging level

private:
	/*************************************************************************
		Copy constructor and assignment usage is denied.
	*************************************************************************/
	hgeLogger(const hgeLogger&) : Singleton <hgeLogger>() {}
	hgeLogger& operator=(const hgeLogger&) {return *this;}

	/*************************************************************************
	Implementation Data
	*************************************************************************/
	std::ofstream	d_ostream;		//!< Stream used to implement the logger
	std::vector<std::pair<String, LoggingLevel> > d_cache;    //!< Used to cache log entries before log file is created.
	std::ostringstream d_workstream;//!< Used to build log entry strings. 
	bool d_caching;                 //!< true while log entries are begin cached (prior to logfile creation)

};

/*************************************************************************
	This macro is used for 'Insane' level logging so that those items are
	excluded from non-debug builds
*************************************************************************/
#if defined(DEBUG) || defined (_DEBUG)
#	define CEGUI_LOGINSANE( message ) hgeLogger::getSingleton().logEvent((message), Insane);
#else
#	define CEGUI_LOGINSANE( message )
#endif

#if defined(_MSC_VER)
#	pragma warning(pop)
#endif

#endif	// end of guard _HgeLogger_h_
